// components/choose-button.js
Component({
	behaviors: ['wx://form-field'],
	/**
	 * 组件的属性列表
	 */
	properties: {
		items: Array,
		type: {
			type: String,
			value: 'radio'
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {},

	/**
	 * 组件的方法列表
	 */
	methods: {
		onTap: function(e) {
			const dataset = e.currentTarget.dataset,
				index = dataset.index;

			const item = this.data.items[index];
			if (this.data.type === 'radio') {
				if (this.data.value === item.value) {
					return;
				}
				this.data.value = item.value;
			} else {
				// todo
			}

			this.setData({value: this.data.value});
			this.triggerEvent('change', this.data.value)
		}
	}
});
